/*
 * @(#)ADLElementModel.java   09/09/13
 *
 * Copyright (C) 2009 Ecole des Mines d'Ales
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Contact: yulinz88@gmail.com
 *
 *
 *
 */



package fr.ema.arch3d.gea.mainGUI.TreeTable;

import fr.ema.arch3d.model.architecture.specification.ComponentRole;
import fr.ema.arch3d.model.architecture.specification.Specification;

/**
 *
 * @author Yulin
 * define the tree model of ADL element, which is composed by its constituents
 *
 */
public class ADLElementModel extends AbstractTreeTableModel implements TreeTableModel {

    // Names of the columns.

    /** Field description */
    static protected String[] cNames = { "Name", "Value" };

    /** Field description */
    static protected Class[] cTypes = { TreeTableModel.class, String.class };

    /**
     * Constructs ...
     *
     *
     * @param cr
     */
    public ADLElementModel(ComponentRole cr) {
        super(new ElementNode(cr));
    }

    /**
     * Constructs ...
     *
     *
     * @param spec
     */
    public ADLElementModel(Specification spec) {
        super(new ElementNode(spec));
    }

    public int getColumnCount() {
        return cNames.length;
    }

    public String getColumnName(int column) {
        return cNames[column];
    }

    /**
     * Returns the type for column number <code>column</code>.
     */
    public Class getColumnClass(int column) {
        return cTypes[column];
    }

    public Object getValueAt(Object node, int column) {

        // System.out.println(((ElementNode)node).getName()+"=");
        switch (column) {
        case 0 :
            return ((ElementNode) node).getUserObject();

        case 1 :
            return ((ElementNode) node).getValue();
        }

        return null;
    }

    public Object getChild(Object node, int i) {
        return ((ElementNode) node).getChildAt(i);
    }

    public int getChildCount(Object node) {

        // System.out.println(((ElementNode)node).getName()+"="+((ElementNode)node).getChildCount());
        return ((ElementNode) node).getChildCount();
    }
}
